package com.kbtd.service.mq;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * 阻塞队列实现消息队列（消息不可靠）
 *
 * @author wp
 * @data 2024/9/18
 */
public class BlockMQ {
    public static final String SECKILL_MESSAGE_TYPE = "seckill";
    private static final Map<String, BlockingQueue<Object>> messages = new HashMap<>();

    public static void productMsg(String type, Object msg) {
        BlockingQueue<Object> sameTypeMessages = messages.get(type);
        if (sameTypeMessages == null) {
           sameTypeMessages = messages.put("type", new ArrayBlockingQueue<>(10224 * 1024));
        }
        sameTypeMessages.add(msg);
        messages.put(type, sameTypeMessages);
    }

    public static BlockingQueue getMsgByType(String type) {
        return messages.get(type);
    }
}
